import UserImg from "@/model/UserImg"
import Constants from "@/const"
import CommonStatus from "@/const/CommonStatus"

export default class User {
  id: number
  nickname: string
  headImg: string
  gender: string
  age: number
  location: string
  birthday: string
  imgs: UserImg []
  //用来区分是否已经喜欢过
  likeDisabled: boolean
  idCardStatus: string
  faceRatio: number
  likeCount: number
  onlineFlag: boolean
  lastOnlineDate: Date
  //是否为vip，
  vipFlag: boolean
  //是否为年会员
  yearVipFlag: boolean
  //邀请码，你分享给别人的邀请码
  inviteCode: string
  //邀请人，谁邀请的你
  registerInviteUser: User
  //vip到期时间
  vipEndDate: Date
  //用户拥有的清池币数量
  qcb: number

  constructor(user: User) {
    this.id = user.id
    this.nickname = user.nickname
    this.headImg = user.headImg
    this.gender = user.gender
    this.age = user.age
    this.location = user.location
    this.birthday = user.birthday
    this.imgs = user.imgs
    // 用来记录是否已经被人喜欢过使用的，被喜欢过不从列表删除，而是禁用喜欢
    this.likeDisabled = false
    this.idCardStatus = user.idCardStatus
    this.faceRatio = user.faceRatio
    this.likeCount = user.likeCount
    this.onlineFlag = user.onlineFlag
    this.lastOnlineDate = user.lastOnlineDate
    this.vipFlag = user.vipFlag
    this.vipEndDate = user.vipEndDate
    this.yearVipFlag = user.yearVipFlag
    this.inviteCode = user.inviteCode
    this.registerInviteUser = user.registerInviteUser
    this.qcb = user.qcb
  }

  get genderIcon(): string {
    if (this.gender === Constants.girl) {
      return Constants.girlIcon
    } else {
      return Constants.boyIcon
    }
  }

  get onlineColor(): string {
    if (this.onlineFlag) {
      return Constants.onlineColor
    } else if (this.lastOnlineDate) {
      const lastDateTime = new Date(this.lastOnlineDate).getTime()
      const curDateTime = new Date().getTime()
      if (curDateTime / Constants.minute - 30 < lastDateTime / Constants.minute) {
        return Constants.onlineColor
      }
    }
    return Constants.offlineColor
  }

  get genderColor(): string {
    if (this.gender === Constants.girl) {
      return Constants.girlColor
    } else {
      return Constants.boyColor
    }
  }

  get certified(): boolean {
    return CommonStatus.certifieds.includes(this.idCardStatus)
  }

  //后台返回的只有属性，不能使用类的方法，但并不是class类，需要转为UserClass类
  public static getUsersBys(users: User[]): User[] {
    return users.map(user => new User(user))
  }
}
